#include "main/utils.h"
using namespace std;

int subArraySum(const vector<int> &vec, const int &k) {
  map<int, int> help_map;
  help_map[0] = 1;
  int cur_sum = 0;
  int count = 0;
  for (int i = 0; i < vec.size(); ++i) {
    cur_sum += vec[i];
    auto find_num = cur_sum - k;
    count += help_map[find_num];
    if (help_map.find(cur_sum) == help_map.end()) {
      help_map[cur_sum] = 1;
    } else {
      ++help_map[cur_sum];
    }
  }
  return count;
}

int main() {
  vector<int> vec = {1, 1, 1};
  int k = 2;
  int ret = subArraySum(vec, k);
  cout << "The number of sub array which sum is k: " << ret << endl;

  return 0;
}
